'use strict';
/**
 * Module dependencies.
 */
var path = require('path');
var _ = require('lodash');
var chalk = require('chalk');

var appPath = path.join(__dirname , 'app'),
    configPath = path.join(appPath , 'config'),
    sysPath = path.join(configPath , 'system');
// actually running
// get rip of that stupid init file
if (_.isUndefined(process.env.NODE_ENV)) {
    console.log(chalk.red('No NODE_ENV provided. Set to development manually'));
    process.env.NODE_ENV = 'development';
}
var config = require(path.join(sysPath , 'config'));

// just include the third party services here
require(path.join(sysPath , 'services'));
/**
 * Main application entry file.
 * Please note that the order of loading is important.
 */
var connections = require('./lib/connection')(config);
// Init the express application 13 August 2015 move to /lib
var app = require(path.join(__dirname , 'lib','express'))(config , connections);
// Bootstrap passport config
require(path.join(sysPath , 'passport'))();
// Start the app by listening on <port>
app.listen(config.port);
// Expose app
exports = module.exports = app;

var color = chalk.yellow;

// Logging initialization
console.log(color('------------------PANES.JS----------------------'));
console.log(color('     ' + config.app.title + ' application started'));
console.log(color('     Environment: ' + process.env.NODE_ENV));
console.log(color('     Port: ' + config.port));
// console.log(chalk.cyan('Database: ' + config.db.uri));
for (var name in config.db) {
    console.log(color('     Database Profile: ' + name));
    console.log(color('     Type: ' + config.db[name].type));
    console.log(color('     Driver: ' + config.db[name].driver));
}

if (process.env.NODE_ENV === 'secure') {
    console.log(color('     HTTPs: on'));
}
console.log(color('-------------------------------------------------'));
// TODO: if we config another port to serve up the socket.io part. Then we have to init here as well


// -- EOF --
